package com.harmonyos.controller;

import cn.hutool.json.JSONUtil;

import com.harmonyos.domain.*;
import com.harmonyos.service.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;


/**
 * @description:
 * @author: Andy
 * @time: 2022/1/2 14:53
 */
@RestController
@RequestMapping("api")

public class Api {



    @Resource
    private TbNewsService tbNewsService;
    @Resource
    private TbUserService tbUserService;
    @Resource
    private TbFourmService tbFourmService;
    @Resource
    private TbPsychologicalService tbPsychologicalService;

    @Resource
    private TbZiService service;


    /**
     * 查询新闻
     *
     */
    @GetMapping ("selectNews")
    public String selectNews(){
        return tbNewsService.selectAll();
    }
    /**
     * 添加add
     * @param
     * @return
     */
    @PostMapping ("addUser")
    public String addUser(@RequestBody String json){
        TbUser user = JSONUtil.toBean(json, TbUser.class);
        return tbUserService.insert(user);

    }


    /**
     * 修改
     * @param
     * @return
     */
    @PostMapping ("updateUser")
    public String updateUser(@RequestBody String json){
        TbUser user = JSONUtil.toBean(json, TbUser.class);
        return tbUserService.update(user);

    }
    /**
     * 查询
     * @param
     * @return
     */
    @PostMapping ("selectUser")
    public String selectUser(@RequestBody String user){

        return tbUserService.select(user);

    }
    /**
     * 查询所有
     * @param
     * @return
     */
    @GetMapping ("selectUserAll")
    public String selectUserAll(){

        return tbUserService.selectAll();

    }


    /**
     * 添加add
     * @param
     * @return
     */
    @PostMapping ("addFourm")
    public String addFourm(@RequestBody String json){
        TbFourm fourm = JSONUtil.toBean(json, TbFourm.class);
        return tbFourmService.insert(fourm);

    }


    /**
     * 删除
     * @param
     * @return
     */
    @PostMapping ("delectFourm")
    public String delectFourm(@RequestBody String id){

        return tbFourmService.delect(id);

    }

    /**
     * 修改
     * @param
     * @return
     */
    @PostMapping ("updateFourm")
    public String updateFourm(@RequestBody String json){
        TbFourm tbFourm = JSONUtil.toBean(json, TbFourm.class);
        return tbFourmService.update(tbFourm);

    }
    /**
     * 查询
     * @param
     * @return
     */
    @PostMapping ("selectFourm")
    public String selectFourm(@RequestBody String user){
        return tbFourmService.select(user);

    }
    /**
     * 查询
     * @param
     * @return
     */
    @GetMapping ("selectFourmlist")
    public String selectFourmlist(@RequestParam("tzid") String tizid){
        return tbFourmService.selecttizi(tizid);

    }
    /**
     * 查询所有
     * @param
     * @return
     */
    @GetMapping ("selectFourmAll")
    public String selectUser(){

        return tbFourmService.selectAll();

    }

    /**
     *
     * 增加
     */
    @PostMapping ("addTbPsychological")
    public String addTbPsychological(@RequestBody String json){
        TbPsychological tbPsychological = JSONUtil.toBean(json, TbPsychological.class);
        return tbPsychologicalService.insert(tbPsychological);

    }
    /**
     * 删除
     *
     */
    @PostMapping ("deletTbPsychological")
    public String deletTbPsychological(@RequestBody String src){
        return tbPsychologicalService.delect(src);

    }
    /**
     * 查询
     * @param
     * @return
     */
    @PostMapping ("selectPsychological")
    public String selectPsychological(@RequestBody String src){

        return tbPsychologicalService.select(src);

    }
    /**
     * 查询所有
     * @param
     * @return
     */
    @GetMapping ("selectPsychologicalAll")
    public String selectPsychologicalAll(){
        return tbPsychologicalService.selectAll();
    }

    /**
     * 修改
     * @param
     * @return
     */
    @PostMapping ("updatePsychological")
    public String updatePsychologica(@RequestBody String json){
        TbPsychological tbPsychological = JSONUtil.toBean(json, TbPsychological.class);
        return tbPsychologicalService.update(tbPsychological);

    }


    /**
     * 查询帖子
     * @param
     * @return
     */
    @GetMapping ("selecttz")
    public List<TbTz> selecttzAll(@RequestParam("user")String user){
       if(user.isEmpty()){
        return service.selectAll();
       }else{
           return service.select(user);
       }
    }
    /**
     * 添加addTz
     * @param
     * @return
     */
    @PostMapping ("addTz")
    public String addTz(@RequestBody String json){
        TbTz tz = JSONUtil.toBean(json, TbTz.class);
        return service.insert(tz);

    }
    /**
     * 修改
     * @param
     * @return
     */
    @PostMapping ("updatetz")
    public String updatetz(@RequestBody TbTz json){
        return service.update(json);
    }
    /**
     * 删除帖子
     */
    @PostMapping ("deletetz")
    public String deletetz(@RequestBody TbTz json){
        return service.delete(json);
    }
}
